import time, random
setGlobalDuration(-1)

beginPythonInst(1)
soundfont(duration=2, out='snd')
endPythonInst()

lowpass(input='snd', amplitude=2, cutoff=3500)

proc = startCsound()

scl = scale('Cm')

time.sleep(1)

hen = henon()

def pit():
    if (ti1.getBar() % 32) == 0:
        hen.changeInitial((random.uniform(.1,.3), random.uniform(.1,.3)))
        hen.changeConstant((random.choice([1.2,1.3,1.4]), random.choice([.2,.25,.3])))

    x, y = hen.next()

    dict = {'soundfont': {}}
    dict['soundfont']['midipitch'] = scl[int(mapper(x,-1.5,1.5,12,60))]
    dict['soundfont']['amplitude'] = mapper(y,-2,2,0,1)
    sendEvent(1, dict, proc)

ti1 = pattern(.125, pit, [1])
ti1.start()
ti1.play()



